<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改服务分类详细')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-serviceTypeDetail-edit" th:object="${zsyhServiceTypeDetail}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">服务类型名称：</label>
                <div class="col-sm-8">
                    <input name="serviceName" th:field="*{thirdServiceName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">一级服务类型名称：</label>
                <div class="col-sm-8">
                    <select id="parentId" name="parentId" class="form-control select2-multiple" multiple required>
                        <option th:each="parent:${parents}" th:value="${parent.id}" th:text="${parent.serviceName}" th:selected="${parent.flag}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">服务类型图标：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="serviceImage" th:field="*{serviceImage}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="serviceImage" name="file" type="file">
                    </div>
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">服务类型等级：</label>
                <div class="col-sm-8">
                    <input name="serviceLevel" th:field="*{serviceLevel}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">固定抽成金额：</label>
                <div class="col-sm-8">
                    <input name="serviceFixdraw" th:field="*{serviceFixdraw}" class="form-control" type="text">
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/serviceTypeDetail";
        $("#form-serviceTypeDetail-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var parentIds = $("#parentId").val().toString();
                if(parentIds.split(",").length>1){
                    $.modal.alert("一级服务分类只能选择一个！");
                }else{
                    $.operate.save(prefix + "/edit", $('#form-serviceTypeDetail-edit').serialize(),function () {
                        parent.$('#bootstrap-table-second').bootstrapTable('refresh');
                    });
                }
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/uploadOSS',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                showUpload: false,/*是否显示上传按钮*/
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            }).on("filebatchselected", function(event, files) {
                $(this).fileinput("upload");
            })
            $(this).fileinput('_initFileActions');
        });

        $(function() {
            $('#parentId').select2({
                placeholder: "请选择一级服务类型名称",
                allowClear: true
            });
        })

    </script>
</body>
</html>